<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>校园宿舍管理系统 - 编辑学生</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color: #17a589;">
    <div class="container">
        <a class="navbar-brand" href="#">校园宿舍管理系统</a>
        <div class="collapse navbar-collapse">
            <ul class="navbar-nav me-auto">
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/home}">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" th:href="@{/student/list}">学生管理</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" th:href="@{/dormitory/list}">宿舍管理</a>
                </li>
            </ul>
            <div class="d-flex">
                <span class="navbar-text me-3" th:text="'欢迎，' + ${session.user.username}"></span>
                <a class="btn btn-outline-light" th:href="@{/user/logout}">退出</a>
            </div>
        </div>
    </div>
</nav>
<div class="container mt-4">
    <div class="row">
        <div class="col-md-6 mx-auto">
            <div class="card">
                <div class="card-header">
                    <h4>编辑学生</h4>
                </div>
                <div class="card-body">
                    <form th:action="@{/student/edit}" method="post">
                        <input type="hidden" name="id" th:value="${student.id}">
                        <div class="mb-3">
                            <label for="name" class="form-label">姓名</label>
                            <input type="text" class="form-control" id="name" name="name" th:value="${student.name}" required>
                        </div>
                        <div class="mb-3">
                            <label for="gender" class="form-label">性别</label>
                            <select class="form-select" id="gender" name="gender" required>
                                <option value="男" th:selected="${student.gender == '男'}">男</option>
                                <option value="女" th:selected="${student.gender == '女'}">女</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label for="age" class="form-label">年龄</label>
                            <input type="number" class="form-control" id="age" name="age" th:value="${student.age}" required>
                        </div>
                        <div class="mb-3">
                            <label for="className" class="form-label">班级</label>
                            <input type="text" class="form-control" id="className" name="className" th:value="${student.className}" required>
                        </div>
                        <div class="mb-3">
                            <label for="major" class="form-label">专业</label>
                            <input type="text" class="form-control" id="major" name="major" th:value="${student.major}" required>
                        </div>
                        <div class="mb-3">
                            <label for="phone" class="form-label">电话</label>
                            <input type="text" class="form-control" id="phone" name="phone" th:value="${student.phone}">
                        </div>
                        <div class="mb-3">
                            <label for="email" class="form-label">邮箱</label>
                            <input type="email" class="form-control" id="email" name="email" th:value="${student.email}">
                        </div>
                        <div class="mb-3">
                            <label for="dormitoryId" class="form-label">分配宿舍</label>
                            <select class="form-select" id="dormitoryId" name="dormitoryId">
                                <option value="0">未分配</option>
                                <option th:each="dormitory : ${dormitories}"
                                        th:value="${dormitory.id}"
                                        th:text="${dormitory.building + '-' + dormitory.dormitoryNumber + ' (' + dormitory.type + ')'}"
                                        th:selected="${dormitory.id == student.dormitoryId and dormitory.occupied <= dormitory.capacity}">
                                </option>
                            </select>
                            <div class="form-text">仅显示有空位的宿舍</div>
                        </div>
                        <button type="submit" class="btn btn-primary">保存</button>
                        <a th:href="@{/student/list}" class="btn btn-secondary">取消</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>